

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/fluid.png">
  <link rel="icon" href="/img/fluid.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="ShanCe">
  <meta name="keywords" content="">
  
    <meta name="description" content="supervisor简介 supervisor可以监控和管理多个进程，确保他们持续运行，并能实时监控，不需要像以往一样需要使用systemctl去查看该服务的状态。 supervisor可以提高服务的可靠性和稳定性，能让服务出现意外退出时，自动重启。 supervisor 提供了一个简单的管理界面和命令行工具，使得管理和监控进程变得方便易用。  supervisor简的主要组成部分 supervi">
<meta property="og:type" content="article">
<meta property="og:title" content="supervisorctl+django+uwsgi部署">
<meta property="og:url" content="https://sweetshance.github.io/2024/05/09/uwsgi/supervisorctl-django-uwsgi%E9%83%A8%E7%BD%B2/index.html">
<meta property="og:site_name" content="ShanCe的博客">
<meta property="og:description" content="supervisor简介 supervisor可以监控和管理多个进程，确保他们持续运行，并能实时监控，不需要像以往一样需要使用systemctl去查看该服务的状态。 supervisor可以提高服务的可靠性和稳定性，能让服务出现意外退出时，自动重启。 supervisor 提供了一个简单的管理界面和命令行工具，使得管理和监控进程变得方便易用。  supervisor简的主要组成部分 supervi">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2024-05-09T07:30:51.000Z">
<meta property="article:modified_time" content="2024-05-10T03:33:47.591Z">
<meta property="article:author" content="ShanCe">
<meta property="article:tag" content="django部署">
<meta name="twitter:card" content="summary_large_image">
  
  
    <meta name="referrer" content="no-referrer-when-downgrade">
  
  
  <title>supervisorctl+django+uwsgi部署 - ShanCe的博客</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"sweetshance.github.io","root":"/","version":"1.9.4","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
  


  
<meta name="generator" content="Hexo 5.4.2"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>ShanCe</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                <span>首页</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                <span>归档</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                <span>分类</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                <span>标签</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                <span>关于</span>
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              <i class="iconfont icon-search"></i>
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">
              <i class="iconfont icon-dark" id="color-toggle-icon"></i>
            </a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/img/default.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="supervisorctl+django+uwsgi部署"></span>
          
        </div>

        
          
  <div class="mt-3">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-author" aria-hidden="true"></i>
        ShanCe
      </span>
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2024-05-09 15:30" pubdate>
          2024年5月9日 下午
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          5.7k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          48 分钟
        
      </span>
    

    
    
      
        <span id="busuanzi_container_page_pv" style="display: none">
          <i class="iconfont icon-eye" aria-hidden="true"></i>
          <span id="busuanzi_value_page_pv"></span> 次
        </span>
        
      
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">supervisorctl+django+uwsgi部署</h1>
            
            
              <div class="markdown-body">
                
                <h3 id="supervisor简介"><a href="#supervisor简介" class="headerlink" title="supervisor简介"></a>supervisor简介</h3><ol>
<li>supervisor可以监控和管理多个进程，确保他们持续运行，并能实时监控，不需要像以往一样需要使用systemctl去查看该服务的状态。</li>
<li>supervisor可以提高服务的可靠性和稳定性，能让服务出现意外退出时，自动重启。</li>
<li>supervisor 提供了一个简单的管理界面和命令行工具，使得管理和监控进程变得方便易用。</li>
</ol>
<h3 id="supervisor简的主要组成部分"><a href="#supervisor简的主要组成部分" class="headerlink" title="supervisor简的主要组成部分"></a>supervisor简的主要组成部分</h3><ol>
<li>supervisord<br>这是supervisor服务的主要管理器，运行supervisor时会启动一个进程supervisord，它负责启动所管理的进程</li>
<li>supervisorctl<br>Supervisorctl 是 Supervisor 的命令行工具，用于与 Supervisord 进行交互。通过 Supervisorctl，您可以启动、停止、重启进程，查看进程状态，以及动态修改配置。</li>
<li>web server<br>能在web界面中监控所有的服务，给我们更直观的感受，并且可以更方便的进行管理，例如开启，停止</li>
<li>xml-rpc interface<br>一种调用接口，能更好的与所属的进程服务进行调用，例如我们想使用nginx这个服务，则需要该组件，去调用，去联系</li>
</ol>
<h3 id="supervisor安装"><a href="#supervisor安装" class="headerlink" title="supervisor安装"></a>supervisor安装</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs bash"><span class="hljs-comment"># pip 安装</span><br>pip install supervisor<br><span class="hljs-comment"># apt 安装</span><br>apt install supervisor<br></code></pre></td></tr></table></figure>

<h3 id="supervisor使用"><a href="#supervisor使用" class="headerlink" title="supervisor使用"></a>supervisor使用</h3><h4 id="文件介绍"><a href="#文件介绍" class="headerlink" title="文件介绍"></a>文件介绍</h4><p>supervisor 包含两个配置文件</p>
<ol>
<li>supervisord.conf # supervisor 配置（一般使用默认的就可以）</li>
<li>supervisord_{project}.ini  # 需要supervisor 监控的进程配置</li>
</ol>
<h3 id="实践"><a href="#实践" class="headerlink" title="实践"></a>实践</h3><h4 id="创建目录-存放相关配置文件，日志文件也可以放这里"><a href="#创建目录-存放相关配置文件，日志文件也可以放这里" class="headerlink" title="创建目录(存放相关配置文件，日志文件也可以放这里)"></a>创建目录(存放相关配置文件，日志文件也可以放这里)</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash"><span class="hljs-built_in">mkdir</span> /etc/supervisor<br></code></pre></td></tr></table></figure>
<h4 id="使用命令生成Supervisor配置文件"><a href="#使用命令生成Supervisor配置文件" class="headerlink" title="使用命令生成Supervisor配置文件"></a>使用命令生成Supervisor配置文件</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs bash"><span class="hljs-comment"># 符号(&gt;)右侧的是配置文件的路径</span><br>echo_supervisord_conf &gt; /etc/supervisor/supervisord.conf<br></code></pre></td></tr></table></figure>
<h4 id="打开supervisord-conf文件修改参数（我这里因为暂时没啥需要不修改了，对参数进行一下备注）-可以只修改include-其他的使用默认就行"><a href="#打开supervisord-conf文件修改参数（我这里因为暂时没啥需要不修改了，对参数进行一下备注）-可以只修改include-其他的使用默认就行" class="headerlink" title="打开supervisord.conf文件修改参数（我这里因为暂时没啥需要不修改了，对参数进行一下备注）(可以只修改include,其他的使用默认就行)"></a>打开supervisord.conf文件修改参数（我这里因为暂时没啥需要不修改了，对参数进行一下备注）(可以只修改include,其他的使用默认就行)</h4><p>注意;代表注释</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br></pre></td><td class="code"><pre><code class="hljs conf">[unix_http_server]<br>file=/tmp/supervisor.sock   ;UNIX socket 文件，supervisorctl 会使用<br>;chmod=0700                 ;socket文件的mode，默认是0700<br>;chown=nobody:nogroup       ;socket文件的owner，格式：uid:gid<br> <br>[inet_http_server]         ;HTTP服务器，提供web管理界面 默认注释的开启需要把前边的；号去掉（如果担心安全问题可以不开启默认不开启）<br>port=0.0.0.0:9001        ;Web管理后台运行的IP和端口，如果开放到公网，需要注意安全性， 我的是虚拟机配置 0.0.0.0 方便访问<br>username=user              ;登录管理后台的用户名<br>password=123               ;登录管理后台的密码<br> <br>[supervisord]<br>logfile=/tmp/supervisord.log ;日志文件，默认是 $CWD/supervisord.log<br>logfile_maxbytes=50MB        ;日志文件大小，超出会rotate，默认 50MB，如果设成0，表示不限制大小<br>logfile_backups=10           ;日志文件保留备份数量默认10，设为0表示不备份<br>loglevel=info                ;日志级别，默认info，其它: debug,warn,trace<br>pidfile=/tmp/supervisord.pid ;pid 文件<br>nodaemon=false               ;是否在前台启动，默认是false，即以 daemon 的方式启动<br>minfds=1024                  ;可以打开的文件描述符的最小值，默认 1024<br>minprocs=200                 ;可以打开的进程数的最小值，默认 200<br> <br>[supervisorctl]<br>serverurl=unix:///tmp/supervisor.sock ;通过UNIX socket连接supervisord，路径与unix_http_server部分的file一致<br>;serverurl=http://127.0.0.1:9001 ; 通过HTTP的方式连接supervisord<br> <br>; [program:xx]是被管理的进程配置参数，xx是进程的名称<br>[program:xx]<br>command=/opt/apache-tomcat-8.0.35/bin/catalina.sh run  ; 程序启动命令<br>autostart=true       ; 在supervisord启动的时候也自动启动<br>startsecs=10         ; 启动10秒后没有异常退出，就表示进程正常启动了，默认为1秒<br>autorestart=true     ; 程序退出后自动重启,可选值：[unexpected,true,false]，默认为unexpected，表示进程意外杀死后才重启<br>startretries=3       ; 启动失败自动重试次数，默认是3<br>user=tomcat          ; 用哪个用户启动进程，默认是root<br>priority=999         ; 进程启动优先级，默认999，值小的优先启动<br>redirect_stderr=true ; 把stderr重定向到stdout，默认false<br>stdout_logfile_maxbytes=20MB  ; stdout 日志文件大小，默认50MB<br>stdout_logfile_backups = 20   ; stdout 日志文件备份数，默认是10<br>; stdout 日志文件，需要注意当指定目录不存在时无法正常启动，所以需要手动创建目录（supervisord 会自动创建日志文件）<br>stdout_logfile=/opt/apache-tomcat-8.0.35/logs/catalina.out<br>stopasgroup=false     ;默认为false,进程被杀死时，是否向这个进程组发送stop信号，包括子进程<br>killasgroup=false     ;默认为false，向进程组发送kill信号，包括子进程<br> <br>;包含其它配置文件<br>[include]<br># 这是我修改的配置文件地址（去掉前边;号）<br>files = /etc/supervisor/conf.d/*.ini   # files = relative/directory/*.ini    ;可以指定一个或多个以.ini结束的配置文件<br></code></pre></td></tr></table></figure>
<blockquote>
<p>修改某些配置时把配置前边的 ; 分号去掉才会生效</p>
</blockquote>
<h4 id="配置子任务"><a href="#配置子任务" class="headerlink" title="配置子任务"></a>配置子任务</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs bash"><span class="hljs-comment"># 创建 目录存放子目录配置</span><br><span class="hljs-built_in">cd</span> /etc/supervisor/<br><span class="hljs-built_in">mkdir</span> conf.d<br><span class="hljs-built_in">cd</span> conf.d<br>vi test.ini<br></code></pre></td></tr></table></figure>
<p>test.ini 配置文件</p>
<figure class="highlight ini"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><code class="hljs ini"><span class="hljs-section">[program:test]</span>        <span class="hljs-comment">;要和文件名称相同(必须和配置文件名字一样)</span><br><span class="hljs-attr">command</span>= =/usr/bin/python3 manage.py runserver <span class="hljs-number">192.168</span>.<span class="hljs-number">193.130</span>:<span class="hljs-number">8000</span>    <span class="hljs-comment">;启动该程序时将运行的命令，我这用的是django 自带的启动</span><br><span class="hljs-attr">directory</span>=/home/shance/myTest        <span class="hljs-comment">;表示command命令的执行目录，myTest是我的django项目</span><br><span class="hljs-attr">autorestart</span>=<span class="hljs-literal">true</span>        <span class="hljs-comment">;自动重启</span><br><span class="hljs-attr">startsecs</span>=<span class="hljs-number">3</span>        <span class="hljs-comment">;启动后程序需要保持运行的总秒数，以认为启动成功(将进程从STARTING状态移动到running状态)。设置为0表示程序不需要在任何特定的时间内保持运行</span><br><span class="hljs-attr">startretries</span>=<span class="hljs-number">3</span>        <span class="hljs-comment">;启动失败时的最多重试次数</span><br><span class="hljs-attr">stdout_logfile</span>=/tmp/test.out.log　　　　 <span class="hljs-comment">;输出日志文件路径</span><br><span class="hljs-attr">stderr_logfile</span>=/tmp/test.err.log        <span class="hljs-comment">;错误日志文件路径</span><br><span class="hljs-attr">stdout_logfile_maxbytes</span>=<span class="hljs-number">2</span>MB        <span class="hljs-comment">;设置stdout_logfile的文件大小</span><br><span class="hljs-attr">stderr_logfile_maxbytes</span>=<span class="hljs-number">2</span>MB        <span class="hljs-comment">;设置stderr_logfile的文件大小</span><br><span class="hljs-attr">user</span>=root        <span class="hljs-comment">;指定运行的用户</span><br><span class="hljs-attr">priority</span>=<span class="hljs-number">999</span>        <span class="hljs-comment">;程序在启动和关闭顺序中的相对优先级</span><br><span class="hljs-attr">numprocs</span>=<span class="hljs-number">1</span><br><span class="hljs-attr">process_name</span>=%(program_name)s_%(process_num)<span class="hljs-number">02</span>d<br></code></pre></td></tr></table></figure>

<h4 id="创建django项目"><a href="#创建django项目" class="headerlink" title="创建django项目"></a>创建django项目</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs bash"><span class="hljs-comment"># 进入目录/home/shance/</span><br><span class="hljs-built_in">cd</span> /home/shance/<br><br><span class="hljs-comment"># 创建django 项目</span><br>django-admin startproject myTest<br></code></pre></td></tr></table></figure>

<h4 id="启动supervisor"><a href="#启动supervisor" class="headerlink" title="启动supervisor"></a>启动supervisor</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs bash">supervisord -c /etc/supervisor/supervisord.conf  <span class="hljs-comment"># 指明配置文件启动</span><br><br>supervisorctl -c /etc/supervisor/supervisord.conf status all <span class="hljs-comment"># 查看子进程</span><br></code></pre></td></tr></table></figure>
<p>root@shance:/etc/supervisor# supervisorctl status<br>test:test_00                     RUNNING   pid 255581, uptime 0:00:08</p>
<ol>
<li><p>这个时候访问django就已经可以了192.168.193.130:8000<br>当你尝试kill 掉django进程会发现停不掉，因为supervisor会自动重启</p>
</li>
<li><p>我配置了inet_http_server所以<br>页面输入<a target="_blank" rel="noopener" href="http://192.168.193.130:8000/">http://192.168.193.130:8000/</a> 可以进入管理界面</p>
</li>
</ol>
<h4 id="使用uwsgi启动django项目"><a href="#使用uwsgi启动django项目" class="headerlink" title="使用uwsgi启动django项目"></a>使用uwsgi启动django项目</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs bash"><span class="hljs-comment"># 停止django</span><br>supervisorctl stop <span class="hljs-built_in">test</span>:test_00 <span class="hljs-comment"># test:test_00 是我的进程名称</span><br><br><span class="hljs-comment"># 安装uwsgi</span><br><br>pip3 install uwsgi<br></code></pre></td></tr></table></figure>

<ol>
<li><p>在项目目录创建uwsgi文件<br>cd /home/shance/myTest<br>vi uwsgi.ini</p>
<figure class="highlight ini"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br></pre></td><td class="code"><pre><code class="hljs ini"><span class="hljs-comment"># uwsig使用配置文件启动</span><br><span class="hljs-section">[uwsgi]</span><br><span class="hljs-comment"># 指定IP端口</span><br><span class="hljs-comment"># socket=0:8641</span><br><span class="hljs-attr">http</span>=<span class="hljs-number">0</span>:<span class="hljs-number">8000</span><br><span class="hljs-comment"># 项目目录</span><br><span class="hljs-attr">chdir</span>=./<br><span class="hljs-comment"># wsgi.py位置</span><br><span class="hljs-attr">wsgi-file</span>=myTest/wsgi.py<br><span class="hljs-comment"># 进程个数</span><br><span class="hljs-attr">workers</span>=<span class="hljs-number">6</span><br><span class="hljs-attr">reload-mercy</span>=<span class="hljs-number">1</span><br><span class="hljs-attr">worker-reload-mercy</span>=<span class="hljs-number">1</span><br><span class="hljs-comment">#配置每个进程的线程数</span><br><span class="hljs-comment">#threads=2</span><br><span class="hljs-comment"># 进程pid文件名</span><br><span class="hljs-comment"># pidfile=uwsgi.pid</span><br><span class="hljs-comment">#设置接受字段的大小</span><br><span class="hljs-attr">buffer-size</span>=<span class="hljs-number">655350</span><br><span class="hljs-comment"># 启用主进程</span><br><span class="hljs-attr">master</span>=<span class="hljs-literal">true</span><br><span class="hljs-comment"># 自动移除unix Socket和pid文件当服务停止的时候</span><br><span class="hljs-attr">vacuum</span>=<span class="hljs-literal">true</span><br><span class="hljs-comment"># 序列化接受的内容，如果可能的话</span><br><span class="hljs-attr">thunder-lock</span>=<span class="hljs-literal">true</span><br><span class="hljs-comment"># 启用线程</span><br><span class="hljs-attr">enable-threads</span>=<span class="hljs-literal">true</span><br><span class="hljs-comment"># 设置自中断时间</span><br><span class="hljs-comment"># harakiri=5</span><br><span class="hljs-comment"># 设置缓冲</span><br><span class="hljs-attr">post-buffering</span>=<span class="hljs-number">4096</span><br><span class="hljs-comment"># 设置日志目录</span><br><span class="hljs-comment"># daemonize=uwsgi.log</span><br><span class="hljs-comment"># 日志路径</span><br><span class="hljs-comment"># logPath=/home/dev/qc/medicalrecordqualityserver/log</span><br><span class="hljs-comment"># log-reopen=true</span><br><span class="hljs-comment"># 请求层面，后台服务不会被断开，但时间比较准确</span><br><span class="hljs-attr">http-timeout</span>=<span class="hljs-number">10</span><br><span class="hljs-comment"># 客户端IP</span><br><span class="hljs-attr">log-x-forwarded-for</span>=<span class="hljs-literal">true</span><br><span class="hljs-attr">listen</span>=<span class="hljs-number">128</span><br></code></pre></td></tr></table></figure>
<p>注意：如果使用supervisor则</p>
<ol>
<li>需要把uwsgi的日志关掉</li>
<li>需要把uwsgi的pid配置关掉</li>
</ol>
</li>
<li><p>修改test.ini 命令<br>主要修改：command</p>
<figure class="highlight ini"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><code class="hljs ini"><span class="hljs-section">[program:test]</span>        <span class="hljs-comment">;要和文件名称相同</span><br><span class="hljs-attr">command</span>=uwsgi --ini uwsgi.ini        <span class="hljs-comment">;启动该程序时将运行的命令，</span><br><span class="hljs-attr">directory</span>=/home/shance/myTest       <span class="hljs-comment">;表示command命令的执行目录</span><br><span class="hljs-attr">autorestart</span>=<span class="hljs-literal">true</span>        <span class="hljs-comment">;自动重启</span><br><span class="hljs-attr">startsecs</span>=<span class="hljs-number">3</span>        <span class="hljs-comment">;启动后程序需要保持运行的总秒数，以认为启动成功(将进程从STARTING状态移动到running状态)。设置为0表示程序不需要在任何特定的时间内保持运行</span><br><span class="hljs-attr">startretries</span>=<span class="hljs-number">3</span>        <span class="hljs-comment">;启动失败时的最多重试次数</span><br><span class="hljs-attr">stdout_logfile</span>=/tmp/test.out.log　　　　 <span class="hljs-comment">;输出日志文件路径</span><br><span class="hljs-attr">stderr_logfile</span>=/tmp/test.err.log        <span class="hljs-comment">;错误日志文件路径</span><br><span class="hljs-attr">stdout_logfile_maxbytes</span>=<span class="hljs-number">2</span>MB        <span class="hljs-comment">;设置stdout_logfile的文件大小</span><br><span class="hljs-attr">stderr_logfile_maxbytes</span>=<span class="hljs-number">2</span>MB        <span class="hljs-comment">;设置stderr_logfile的文件大小</span><br><span class="hljs-attr">user</span>=root        <span class="hljs-comment">;指定运行的用户</span><br><span class="hljs-attr">priority</span>=<span class="hljs-number">999</span>        <span class="hljs-comment">;程序在启动和关闭顺序中的相对优先级</span><br><span class="hljs-attr">numprocs</span>=<span class="hljs-number">1</span><br><span class="hljs-attr">process_name</span>=%(program_name)s_%(process_num)<span class="hljs-number">02</span>d<br><br></code></pre></td></tr></table></figure></li>
<li><p>重新读取配置文件</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs bash"><span class="hljs-comment"># reload 完项目自动启动</span><br>supervisorctl update<br>supervisorctl reload  <br></code></pre></td></tr></table></figure></li>
</ol>
<h4 id="supervisior-常用命令"><a href="#supervisior-常用命令" class="headerlink" title="supervisior 常用命令"></a>supervisior 常用命令</h4><figure class="highlight awk"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><code class="hljs awk">supervisord                             <span class="hljs-regexp">//</span> 启动supervisor 这个最好使用 -c  指明配置文件<br>supervisorctl status                    <span class="hljs-regexp">//</span>查看所有进程的状态<br>supervisorctl stop test:test_00         <span class="hljs-regexp">//</span>停止test:test_00<br>supervisorctl start test:test_00        <span class="hljs-regexp">//</span>启动test:test_00<br>supervisorctl start all                 <span class="hljs-regexp">//</span>启动所有<br>supervisorctl restart test:test_00      <span class="hljs-regexp">//</span>重启test:test_00<br>supervisorctl update                    <span class="hljs-regexp">//</span>配置文件修改后使用该命令加载新的配置<br>supervisorctl reload                    <span class="hljs-regexp">//</span>重新启动配置中的所有程序<br><br>systemctl restart supervisord <span class="hljs-regexp">//</span>重启supervisor<br></code></pre></td></tr></table></figure>
<p>可以像上边指明 配置文件，也可以不指明</p>

                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/categories/uwsgi/" class="category-chain-item">uwsgi</a>
  
  
    <span>></span>
    
  <a href="/categories/uwsgi/django/" class="category-chain-item">django</a>
  
  
    <span>></span>
    
  <a href="/categories/uwsgi/django/supervisor/" class="category-chain-item">supervisor</a>
  
  

  

  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/tags/django%E9%83%A8%E7%BD%B2/">#django部署</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>supervisorctl+django+uwsgi部署</div>
      <div>https://sweetshance.github.io/2024/05/09/uwsgi/supervisorctl-django-uwsgi部署/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>ShanCe</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2024年5月9日</div>
        </div>
      
      
      
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2024/05/10/django/django%E5%88%9D%E5%A7%8B%E5%8C%96%E6%95%B0%E6%8D%AE%E5%BA%93%E7%BC%96%E7%A0%81/" title="django初始化数据库编码">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">django初始化数据库编码</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2024/04/23/mysql/Mysql%E5%BF%98%E8%AE%B0root%E5%AF%86%E7%A0%81%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88/" title="Mysql忘记root密码解决方案">
                        <span class="hidden-mobile">Mysql忘记root密码解决方案</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header">
    <i class="iconfont icon-list"></i>
    <span>目录</span>
  </p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="http://82.157.172.231/" target="_blank" rel="nofollow noopener"><span>无聊</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>ShanCe</span></a> 
    </div>
  
  
    <div class="statistics">
  
  

  
    
      <span id="busuanzi_container_site_pv" style="display: none">
        总访问量 
        <span id="busuanzi_value_site_pv"></span>
         次
      </span>
    
    
      <span id="busuanzi_container_site_uv" style="display: none">
        总访客数 
        <span id="busuanzi_value_site_uv"></span>
         人
      </span>
    
    
  
</div>

  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init(Object.assign({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      scrollSmooth    : true,
      includeTitleTags: true,
      headingsOffset  : -boardTop,
    }, CONFIG.toc));
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }

    Fluid.events.registerRefreshCallback(function() {
      if ('tocbot' in window) {
        tocbot.refresh();
        var toc = jQuery('#toc');
        if (toc.length === 0 || !tocbot) {
          return;
        }
        if (toc.find('.toc-list-item').length > 0) {
          toc.css('visibility', 'visible');
        }
      }
    });
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.11/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));

    Fluid.events.registerRefreshCallback(function() {
      if ('anchors' in window) {
        anchors.removeAll();
        var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
        var res = [];
        for (var item of el) {
          res.push('.markdown-body > ' + item.trim());
        }
        if (CONFIG.anchorjs.placement === 'left') {
          anchors.options.class = 'anchorjs-link-left';
        }
        anchors.add(res.join(', '));
      }
    });
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/js/local-search.js" ></script>

  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
